package com.huashi.dealer.modular.controller.store.setting;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huashi.dealer.commonEntity.SettingBanner;
import com.huashi.dealer.core.page.PageFactory;
import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.modular.business.setting.param.StoreBannerSaveParam;
import com.huashi.dealer.modular.business.setting.service.StoreSettingBannerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Store端轮播图设置")
@RestController("storeSettingBannerController")
@RequestMapping("/store/setting/banner")
@Validated
public class SettingBannerController {

    @Resource
    private StoreSettingBannerService storeSettingBannerService;

    @GetMapping("/list")
    @Operation(summary = "轮播图列表")
    public CommonResult<Page<SettingBanner>> list() {
        Page<SettingBanner> page = PageFactory.defaultPage();
        Page<SettingBanner> result = storeSettingBannerService.getBannerPage(page);
        return CommonResult.data(result);
    }

    @PostMapping("/save")
    @Operation(summary = "新增或编辑轮播图")
    public CommonResult<String> save(@RequestBody StoreBannerSaveParam param) {
        storeSettingBannerService.saveOrUpdateBanner(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "删除轮播图")
    public CommonResult<String> delete(@PathVariable Long id) {
        storeSettingBannerService.deleteBanner(id);
        return CommonResult.ok("删除成功");
    }
}


